package HW;
import java.io.*;

public class compareText {

    public static void compare(File file1,File file2){
//        int len1;
//        int len2;
        String str1;
        String str2;

        try {

            BufferedReader reader1 = new BufferedReader(new FileReader(file1));
            BufferedReader reader2 = new BufferedReader(new FileReader(file2));
            try {
               while ((str1 = reader1.readLine())!=null&&(str2=reader2.readLine())!=null){
                   if (str1.equals(str2)){
                       continue;
                   } else {
                       System.out.println(str1);
                       System.out.println(str2);
                   }
               }

//            //读取两个文件内容
//            FileReader fileReader1 = new FileReader(file1);
//            FileReader fileReader2 = new FileReader(file2);
//            //对比每一次两个文件的读取内容
//            try {
//                while((len1 = fileReader1.read())!=-1){
//                    len2 = fileReader2.read();
//                    if(len1 == len2){
//                        //相同 ---> 继续
//                        System.out.print("\n"+ (char)len1);
//                        System.out.print( (char)len2);
//                        continue;
//                    }else{
//                        //不同 ---> 返回该内容并退出
//                        System.out.print("\n"+ (char)len1);
//                        System.out.print( (char)len2);
//                        break;
//                    }
//                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        // 创建两个File对象，分别读取两个文件
        File file1 = new File("src/HW/a.txt");
        File file2 = new File("src/HW/b.txt");
        //调用对比方法
        compare(file1,file2);
    }
}
